<template>
	<view>
		<image src="/static/work1.jpg" mode="" class="img_bg " style="top: 0;"></image>
		<view class="" >
		<view class="margin-l30 margin-r30">
		<block v-for="(item,index) in list" :key="index">
			<view class="card margin-t30 relative" @tap="toDetail(item.id,item.add_time)">
				<view :class="item.status=='1'?'jiaobiao':'jiaobiao2'" >
					{{item.inspection_status==0?zhipai:item.inspection_status==1?zhenggai:item.inspection_status==2?fucha:item.inspection_status==3?tongguo:'weitongguo'}}
				</view>
				<view class="text-36">{{item.danger_name?item.danger_name:"-"}}</view>
				<view class="display justify-between margin-t22">
					<view class="font-gray1">巡检人</view>
					<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''" >{{item.nickname?item.nickname:"-"}}</view> 
				</view>
				
				<view class="display justify-between margin-t22"> 
					<view class="font-gray1 ">隐患级别</view>
					<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.safety_level==1?zhengchang:item.safety_level==2?yichang:cuowu}}</view>
				</view>
				<view class="display justify-between margin-t22">
					<view class="font-gray1 ">巡检时间</view>
					<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.add_time?item.add_time:"-"}}</view>
				</view>
				<!-- 重新指派 -->
				<!-- <view class="" style="width: 150rpx;margin-left: 55%;color: #FFFFFF;background: #FF2400;position: absolute;top: 0;text-align: center;" @click.stop="reset(item)">
					点此重新指派
				</view> -->
			</view>
		</block>
		<view class="loading" v-show="!isShow">
			{{loadingText}}
		</view>
		<view class="text-center noNotice" v-show="isShow" style="margin-top: 200upx;">
			<image src="/static/notice.png" class="noticeImg"></image>
			<view class="font-gray margin-t30">暂无待指派任务~</view>
		</view>
		</view>
		</view>
	</view>
</template>

<script>
	var page=1,timer
	export default {
		data() {
			return {
				uid:'',
				token:'',
				list:[],
				zhipai:'待指派',
				zhenggai:'待整改',
				fucha:'待复查',
				tongguo:'通过',
				weitongguo:'未通过',
				zhengchang:'一般隐患',
				yichang:'重大隐患',
				cuowu:'类型错误',
				loadingText:'上拉加载更多',
				isShow:false
				
			}
		},
		onLoad:function(){
			this.uid =uni.getStorageSync('user').uid;
			this.token =uni.getStorageSync('user').token;
			this.getZhipai()
		}, 
		onPullDownRefresh:function(){
			this.getZhipai()
		},
		onReachBottom:function(){
			let that=this
			if(timer !=null){clearTimeout(timer)}
			timer = setTimeout(function(){
				that.getNewZhipai();
			},500);
		},
		methods: {
			
			//重新指派
			reset(item){
				console.log(item.is_reassign)
				if(item.is_reassign === 1){
					uni.request({
						url: 'https://aqmore.sxpz.vip/AppApi/SafetyInspection/setReAssign?uid=' + this.uid + '&token=' + this.token +
							'&id=' + item.id,
						method: 'GET',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						success: function(res) {
							item.inspection_status=0
							console.log(res.data.datas.msg)
							uni.showToast({
								title:res.data.datas.msg
							})
						},
						fail() {
							uni.showToast({
								title:res.data.datas.msg
							})
						}
					})
				}else{
					uni.showToast({
						title:'您无法重新指派',
						icon:'none'
					})
				}
				
			},
			getZhipai(){
				var that=this
				page=1
				uni.showNavigationBarLoading();
				this.loadingText='上拉加载更多'
				uni.request({
					url:'https://aqmore.sxpz.vip/AppApi/SafetyInspection/getAssignList?uid='+this.uid+'&token='+this.token+'&p='+page,
					method:'GET',
					header:{'content-type':'application/x-www-form-urlencoded'},
					success:function(res){
						if(res.data.code==100){
							console.log(res)
							uni.showToast({
								title:res.data.datas.msg,
								icon:'none'
							})
							setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/index/index'
							})
							try {
							    uni.removeStorageSync('user');
								console.log('chenggonmg')
							} catch (e) {
							    // error
							}
							},1500)
						}
						if(res.data.code==200){
							if(res.data.datas.length==0){
								that.isShow=true
							}
							that.list=res.data.datas
							console.log(that.list)
						}
						uni.stopPullDownRefresh();
						uni.hideNavigationBarLoading ();
						page++;
					}
				})
			},
			getNewZhipai(){
				var that=this
				if(this.loadingText=='没有更多待指派任务'){return false}
				this.loadingText='加载中...'
				uni.showNavigationBarLoading();
				uni.request({
					url:'https://aqmore.sxpz.vip/AppApi/SafetyInspection/getAssignList?uid='+this.uid+'&token='+this.token+'&p='+page,
					method:'GET',
					header:{'content-type':'application/x-www-form-urlencoded'},
					success:function(res){
						uni.hideNavigationBarLoading();
						if(res.data.datas.length==0){
							that.loadingText='没有更多待指派任务';
							return false
						}
						if(res.data.code==200){
							var newlist=res.data.datas
							that.list=that.list.concat(newlist)
							console.log(that.list)
						}
						page++;
					}
				})
			},
			toDetail(e,f){
				uni.navigateTo({
					url:'zhipaiInspectionDetail?id='+e+'&time=' + f 
				})
			}
		}
	}
</script>

<style>
	.noticeImg{
		width: 360upx;
		height: 300upx;
	}
	page{
			margin: 0;
			padding: 0;
			/* background-color: #0d98ed; */
		}
	.jiaobiao{
			position: absolute;
			height: 50upx;
			width: 100upx;
			right: 0;
			font-size: 100%;
			background-color: #00aa00;
			color: #FFFFFF;
			top:-3upx;
			border-radius: 10%;
			text-align: center;
		}
		.jiaobiao2{
			position: absolute;
			height: 50upx;
			width: 100upx;
			right: 0;
			font-size: 100%;
			background-color: #ff0000;
			color: #FFFFFF;
			top:-3upx;
			border-radius: 10%;
			text-align: center;
		}
		.loading{
			line-height: 2em;text-align: center;color: #808080;margin-top: 30upx;
		}
</style>
